home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- import java.awt.image.BufferStrategy;
- import java.awt.image.VolatileImage;
-
- public class Component$FlipBufferStrategy extends BufferStrategy {
- protected int numBuffers;
- protected BufferCapabilities caps;
- protected Image drawBuffer;
- protected VolatileImage drawVBuffer;
- protected boolean validatedContents;
- int width;
- int height;
- // $FF: synthetic field
- final Component this$0;
-
- protected Component$FlipBufferStrategy(Component var1, int var2, BufferCapabilities var3) throws AWTException {
- this.this$0 = var1;
- if (!(var1 instanceof Window) && !(var1 instanceof Canvas)) {
- throw new ClassCastException("Component must be a Canvas or Window");
- } else {
- this.numBuffers = var2;
- this.caps = var3;
- this.createBuffers(var2, var3);
- }
- }
-
- protected void createBuffers(int var1, BufferCapabilities var2) throws AWTException {
- if (var1 < 2) {
- throw new IllegalArgumentException("Number of buffers cannot be less than two");
- } else if (this.this$0.peer == null) {
- throw new IllegalStateException("Component must have a valid peer");
- } else if (var2 != null && var2.isPageFlipping()) {
- this.width = this.this$0.getWidth();
- this.height = this.this$0.getHeight();
- if (this.drawBuffer == null) {
- this.this$0.peer.createBuffers(var1, var2);
- } else {
- this.drawBuffer = null;
- this.drawVBuffer = null;
- this.destroyBuffers();
- this.this$0.peer.createBuffers(var1, var2);
- }
-
- this.updateInternalBuffers();
- } else {
- throw new IllegalArgumentException("Page flipping capabilities must be specified");
- }
- }
-
- private void updateInternalBuffers() {
- this.drawBuffer = this.getBackBuffer();
- if (this.drawBuffer instanceof VolatileImage) {
- this.drawVBuffer = (VolatileImage)this.drawBuffer;
- } else {
- this.drawVBuffer = null;
- }
-
- }
-
- protected Image getBackBuffer() {
- if (this.this$0.peer != null) {
- return this.this$0.peer.getBackBuffer();
- } else {
- throw new IllegalStateException("Component must have a valid peer");
- }
- }
-
- protected void flip(BufferCapabilities.FlipContents var1) {
- if (this.this$0.peer != null) {
- this.this$0.peer.flip(var1);
- } else {
- throw new IllegalStateException("Component must have a valid peer");
- }
- }
-
- protected void destroyBuffers() {
- if (this.this$0.peer != null) {
- this.this$0.peer.destroyBuffers();
- } else {
- throw new IllegalStateException("Component must have a valid peer");
- }
- }
-
- public BufferCapabilities getCapabilities() {
- return this.caps;
- }
-
- public Graphics getDrawGraphics() {
- this.revalidate();
- return this.drawBuffer.getGraphics();
- }
-
- protected void revalidate() {
- this.revalidate(true);
- }
-
- void revalidate(boolean var1) {
- this.validatedContents = false;
- if (var1 && (this.this$0.getWidth() != this.width || this.this$0.getHeight() != this.height)) {
- try {
- this.createBuffers(this.numBuffers, this.caps);
- } catch (AWTException var6) {
- }
-
- this.validatedContents = true;
- }
-
- this.updateInternalBuffers();
- if (this.drawVBuffer != null) {
- GraphicsConfiguration var2 = this.this$0.getGraphicsConfiguration_NoClientCode();
- int var3 = this.drawVBuffer.validate(var2);
- if (var3 == 2) {
- try {
- this.createBuffers(this.numBuffers, this.caps);
- } catch (AWTException var5) {
- }
-
- if (this.drawVBuffer != null) {
- this.drawVBuffer.validate(var2);
- }
-
- this.validatedContents = true;
- } else if (var3 == 1) {
- this.validatedContents = true;
- }
- }
-
- }
-
- public boolean contentsLost() {
- return this.drawVBuffer == null ? false : this.drawVBuffer.contentsLost();
- }
-
- public boolean contentsRestored() {
- return this.validatedContents;
- }
-
- public void show() {
- this.flip(this.caps.getFlipContents());
- }
-
- public void dispose() {
- if (this.this$0.bufferStrategy == this) {
- this.this$0.bufferStrategy = null;
- if (this.this$0.peer != null) {
- this.destroyBuffers();
- }
- }
-
- }
- }
-